@extends('layouts.header')
@section('style')
	label.error {
	position: absolute;
	right: 0px;
	top: 18px;
	color: #ef392b;
	font-size: 12px;
	}

	input[type=text] {
	/* width:50px; */
	text-align: center
	}

	.t-a-l {
	text-align: left !important;
	padding-left: 3px !important;
	}

	.col-1, .col-2, .col-3, .col-4, .col-5, .col-6, .col-7, .col-8, .col-9, .col-10, .col-11, .col-12, .col-xs-1, .col-sm-1, .col-md-1, .col-lg-1, .col-xs-2, .col-sm-2, .col-md-2, .col-lg-2, .col-xs-3, .col-sm-3, .col-md-3, .col-lg-3, .col-xs-4, .col-sm-4, .col-md-4, .col-lg-4, .col-xs-5, .col-sm-5, .col-md-5, .col-lg-5, .col-xs-6, .col-sm-6, .col-md-6, .col-lg-6, .col-xs-7, .col-sm-7, .col-md-7, .col-lg-7, .col-xs-8, .col-sm-8, .col-md-8, .col-lg-8, .col-xs-9, .col-sm-9, .col-md-9, .col-lg-9, .col-xs-10, .col-sm-10, .col-md-10, .col-lg-10, .col-xs-11, .col-sm-11, .col-md-11, .col-lg-11, .col-xs-12, .col-sm-12, .col-md-12, .col-lg-12 {
	padding-left: 0px;
	padding-right: 0px;
	/* border:solid 1px #ef392b ; */
	}

	@media (max-width: 767px) {
	.form-horizontal .form-label {
	text-align: right;
	}
	}

	.row {
	margin-left: 0px;
	margin-right: 0px;
	}

	.form .row {
	margin-top: 7px;
	}
@endsection
@section('title','安全帽冲击试验机	')
@section('content')
	<div class="cl pd-5 bg-1 bk-gray" style="height:100px; text-align: center"><b style="font-size: 50px ">安全帽冲击试验机	</b></div>
	<br/>
	<div class="cl pd-5 bg-1 bk-gray">
		<div class="row cl">
			<label class="form-label col-xs-1" style="padding: 4px 15px"><b>试品编号：</b></label>
			<div class="formControls col-xs-4">
				<input type="text" class="input-text" name="barCode" value="" placeholder="请扫描ID码或样品上的二维码">
			</div>
		</div>
	</div>
	<br/>
	<div class="panel panel-primary">
		<div class="panel-header">下方左侧选择试验标准与试验项目，右方填写试验数据点击保存！</div>
		<div class="info" style="display: block;">
			<input type="hidden" name="cycle" value="1">
			<br>
			<div class="" style="margin-left: 30px;margin-right: 30px;">
				<div class="f-l form form-horizontal " style="width:39%;border-right:1px dotted #ddd">
					<!--div class="row cl">
						<label class="form-label col-xs-4"><b>选择试验标准：</b></label>
						<div class="formControls col-xs-5">
							<select class="select2 input-text select2-hidden-accessible" name="std" data-select2-id="4" aria-hidden="true">
								<option value="" selected="">--请选择--</option>
								@foreach($data_rel as $val)
									<option value="{{$val -> id}}">{{$val -> num}}</option>
								@endforeach
							</select>
						</div>
					</div-->
					<div class="row cl">
						<label class="form-label col-xs-4"><b>选择试验项目：</b></label>
						<div class="formControls col-xs-5">
							<select class="select2 input-text select2-hidden-accessible" name="item_id" data-select2-id="4"  aria-hidden="true">
								<option value="" selected="" data-select2-id="6">--请选择--</option>
								@foreach($data_item as $val)
									<option value="{{$val -> testitem_id.'-'.$val->name}}">{{$val -> name}}</option>
								@endforeach
							</select>
						</div>
					</div>
					<div class="row cl">
						<label class="form-label col-xs-4"><b>选择试验力值：</b></label>
						<div class="formControls col-xs-5">
							<select class="select2 input-text select2-hidden-accessible" name="force" data-select2-id="4" aria-hidden="true">
								<option value="" selected="" data-select2-id="6">--请选择--</option>
								@foreach($data_lizhi as $val)
									<option value="{{$val -> val}}">{{$val -> val.$val->unit}}</option>
								@endforeach
							</select>
						</div>
					</div>
					<div class="row cl">
						<label class="form-label col-xs-4"><b>选择试验时间：</b></label>
						<div class="formControls col-xs-5">
							<select class="select2 input-text select2-hidden-accessible" name="time" data-select2-id="4"  aria-hidden="true" disabled>
								<option value="" selected="" data-select2-id="6">--请选择--</option>
								@foreach($data_time as $val)
									<option value="{{$val -> val}}">{{$val -> val.$val->unit}}</option>
								@endforeach
							</select>
						</div>
					</div>
						<div class="row cl">
							<label class="form-label col-xs-4"><b>天气：</b></label>
							<div class="formControls col-xs-3">
								<select class="select2 input-text select2-hidden-accessible" name="wea" data-select2-id="4"  aria-hidden="true">
									<option value="晴" selected="" data-select2-id="6">晴</option>
									@foreach($weaStat as $val)
										<option value="{{$val}}">{{$val}}</option>
									@endforeach
								</select>
							</div>
						</div>
						<div class="row cl">
							<label class="form-label col-xs-4"><b>大气压力：</b></label>
							<div class="formControls col-xs-3">
								<input type="text" class="input-text" name="pressure" value="{{$pressure->pressure}}">
							</div>
							<label class="form-label t-a-l col-xs-3">kPa</label>
						</div>
						<div class="row cl">
							<label class="form-label col-xs-4"><b>环境温度：</b></label>
							<div class="formControls col-xs-3">
								<input type="text" class="input-text" name="temp" value="{{$temp_humi->temp}}">
							</div>
							<label class="form-label t-a-l col-xs-3">℃</label>
						</div>
						<div class="row cl">
							<label class="form-label col-xs-4"><b>相对湿度：</b></label>
							<div class="formControls col-xs-3">
								<input type="text" class="input-text" name="hum" value="{{$temp_humi->humi}}">
							</div>
							<label class="form-label t-a-l col-xs-3">%</label>
						</div>
				</div>

				<div class="f-l form form-horizontal" style="width:60%;">
					<!--div class="row cl data-key-val">
						<label class="form-label col-xs-5"><b style="font-size: 30px">试验结果录入</b></label>
					</div-->
					<div class="row cl data-key-val">
						<label class="form-label col-xs-4"><b>设备编号：</b></label>
						<div class="formControls col-xs-3">
							<input type="text" class="input-text" name="device_num" value="HB-NO-046" style="color:gray">
						</div>
						<label class="form-label t-a-l col-xs-3" style="color:#cd2a19;font-size:8px">(默认展示，无需修改)</label>
					</div>
					<div class="row cl data-key-val">
						<label class="form-label col-xs-4"><b>是否穿透：</b></label>
						<div class="formControls col-xs-3">
							<select class="select2 input-text select2-hidden-accessible" name="through" style="height:30px;width:100px">
								<option value="1" >穿透</option>
								<option value="0" selected="">未穿透</option>
							</select>
						</div>
					</div>
					<div class="row cl data-key-val">
						<label class="form-label col-xs-4"><b>力值：</b></label>
						<div class="formControls col-xs-3">
							<input type="text" class="input-text" name="force_value" value="">
						</div>
					</div>
					<div class="row cl data-key-val">
						<label class="form-label col-xs-4"><b>时间：</b></label>
						<div class="formControls col-xs-3">
							<input type="text" class="input-text" name="time_value" value="" disabled>
						</div>
						<label class="form-label t-a-l col-xs-3">S</label>
					</div>
					<div class="row cl data-key-val">
						<label class="form-label col-xs-4"><b>试验日期：</b></label>
						<div class="formControls col-xs-3">
							<input type="text" name="utime" readonly="" value="{{date("Y-m-d",time())}}" onfocus="WdatePicker({})" class="input-text Wdate" style="width:180px">
						</div>
					</div>
					<div class="row cl data-key-val">
						<label class="form-label col-xs-4"><b>检测结果：</b></label>
						<div class="formControls col-xs-3">
							<select name="res" style="height:30px;width:78px">
								<option value="1" selected="">符合</option>
								<option value="0">不符合</option>
							</select>
						</div>
					</div>
				</div>
				<div class="form form-horizontal" style="width:39%;">
					<div class="row cl">
						<label class="form-label col-xs-4"><b>备注/不符合现象描述：</b></label>
					</div>
				</div>
				<div class="form form-horizontal" style="width:100%;">
					<div class="row cl">
						<div class="formControls col-xs-12 text-l">
							<input type="text" name="remark" value="无" class="input-text">
						</div>
					</div>
				</div>
				<div style="clear:both"></div>
			</div>
			<hr style="margin:5px;background-color:#ddd;height:1px;width:100%;border:none;">
			<div>
				<center>
					<input type="submit" name = 'startTest' value="开始试验" class="ml-50 btn btn-primary radius " style="margin-bottom: 5px">
					<input type="submit" name = 'saveData' value="保 存" class="ml-50 btn btn-primary radius " style="margin-bottom: 5px">
				</center>
			</div>
		</div>
	</div>
	<script>
		$(function(){
			//保存数据
			$('input[name="saveData"]').on('click',function(){
				//判断试品编号
				var barCode = $('input[name="barCode"]').val();
				if(!barCode){
					layer.msg('未输入试品编号!', {icon: 2, time: 2000});
					return false;
				}
				//判断试验项目
				var itemVal = $('select[name="item_id"]').val();
				if(!itemVal){
					layer.msg('请选择试验项目!', {icon: 2, time: 2000});
					return false;
				}
				let data = {};
				data.isAQM = '1';
				data.username = '';
				data.wea = $('select[name="wea"]').val();
				data.pressure = $('input[name="pressure"]').val();
				data.temp = $('input[name="temp"]').val();
				data.hum = $('input[name="hum"]').val();
				data.bar_code = $('input[name="barCode"]').val();
				data.device_num = $('input[name="device_num"]').val();
				var value_name =$('select[name="item_id"]').val();
				var item_name = value_name.split('-');
				data.item_id = item_name[0];
				data.test_date = $('input[name="utime"]').val();
				data.strength_max = $('input[name="force_value"]').val();
				data.time_keep = '';
				data.strength_keep = '';
				data.is_through = $('select[name="through"]').val();
				data.res = $('select[name="res"]').val();
				data.remark = $('input[name="remark"]').val();
				if(data.is_through == 1){
					data.res = 0 ;
				}
				console.log(data);
				ajax('post', 'saveData', data, back,0);
			});
			function back(data){
				layer.msg(data, {
					icon: 6, // 使用 icon 表情
					time: 1000 // 显示时间，单位毫秒
				}, function() {
					// 刷新页面
					location.reload();
				});
			}

			//开始试验
			$('input[name="startTest"]').on('click',function(){
				//判断试品编号
				var barCode = $('input[name="barCode"]').val();
				if(!barCode){
					layer.msg('请输入试品编号!', {icon: 2, time: 2000});
					return false;
				}
				//判断标准
				/*var stdVal = $('select[name="std"]').val();
				if(!stdVal){
					layer.msg('请选择试验标准!', {icon: 2, time: 2000});
					return false;
				}*/
				//判断试验项目
				var itemVal = $('select[name="item_id"]').val();
				if(!itemVal){
					layer.msg('请选择试验项目!', {icon: 2, time: 2000});
					return false;
				}
				//判断力值
				var forceVal = $('select[name="force"]').val();
				if(!forceVal){
					layer.msg('请选择试验力值!', {icon: 2, time: 2000});
					return false;
				}
				//判断时间
				/*var timeVal = $('select[name="time"]').val();
				if(!timeVal){
					layer.msg('请选择试验时间!', {icon: 2, time: 2000});
					return false;
				}*/
				layer.msg('可以试验！！！', {icon: 1, time: 2000});
				return true;
			});
			//选择试验项目，相应的参数置灰
			$('select[name="item_id"]').on("change",function(){
				var value = $(this).val();
				var itemName = value.split('-');
				if(itemName[1].indexOf('穿刺') !== -1){
					$('input[name="force_value"]').attr('disabled',true);
					$('select[name="through"]').attr('disabled',false);
				}else{
					$('select[name="through"]').attr('disabled',true);
					$('input[name="force_value"]').attr('disabled',false);
				}
			});
			//力值选中后自动补齐
			$('select[name="force"]').on("change",function(){
				var value = $(this).val();
				$('input[name="force_value"]').val(value);
			});
			//时间选中后自动补齐
			$('select[name="time"]').on("change",function(){
				var value = $(this).val();
				$('input[name="time_value"]').val(value*60);
			});
		})
	</script>
@endsection